copyHier

I am trying to use the function copyHier to copy an object heading and its descendants to another module but it seems that this function only works within the same module.

For example:
In a script, if I use copyHier and then pasteSame to the same module it works fine.

If I do copyHier in "module A" and then pasteSame in "module B" it fails.

I am trying to copy all of the contents of one module into another blank module, basically to duplicate it, but I cannot simply do clipCopy(module a) clipPaste etc.
Is there a way to make this function work for this purpose?

If not, what is the simplest way to achieve this goal?

Thanks,
John V
John V - Mon Nov 09 11:23:23 EST 2009

Re: copyHier
ePiallat - Mon Nov 09 11:46:22 EST 2009

May I ask you why you can't use clipCopy/clipPaste?

Anyway, you don't need the clipboard at all:
You can copy a module with bool copy(ModName_ modRef, string newName, string newdesc)

If you really need to copy each object individually, I suggest you use the example script DOORSHOME/lib/dxl/example/copyobj.dxl

Re: copyHier
John V - Mon Nov 09 12:59:24 EST 2009

ePiallat - Mon Nov 09 11:46:22 EST 2009
May I ask you why you can't use clipCopy/clipPaste?

Anyway, you don't need the clipboard at all:
You can copy a module with bool copy(ModName_ modRef, string newName, string newdesc)

If you really need to copy each object individually, I suggest you use the example script DOORSHOME/lib/dxl/example/copyobj.dxl

I need to copy objects from a module in a static "library or collection" if you will-a "library or collection" that will stay the same forever-to a blank template module in a completely separate project. This has to be performed in this manner because the template module is set up following specific formats for the individual project.

If you read my previous post I asked how I can perform a similar function to copying all the objects over, I'm already aware of the bool copy function and how it works, and it does not fulfill what I am trying to do, I'm not trying to copy the module-as I've already said-I'm trying to duplicate the data to a template.

I haven't explicitly looked through copyobj.dxl but I've looked through scripts that co-workers have written based on this script and it seems very complex and convoluted for the ideas that I'm trying to implement.

I was looking at copyHier because if you use the DOORS gui, you can do what I'm attempting to do in DXL, with a few simple mouse clicks. I was trying to find the code that was used to implement those functions in the gui and it appeared that copyHier was the closest thing.
FOR EXAMPLE:
In the gui, if you open two separate modules, in the first module, you can grab an object heading with the mouse and drag it to the second module, at which point a list comes up and you can select "Copy->After (with hierarchy)"

It appears that this is the copyHier function but as I said, I can only get this function to work within the same module, not from one module to the next.

If it helps, this script is being written for 8.3.

Re: copyHier
Mathias Mamsch - Tue Nov 10 03:56:15 EST 2009

John V - Mon Nov 09 12:59:24 EST 2009
I need to copy objects from a module in a static "library or collection" if you will-a "library or collection" that will stay the same forever-to a blank template module in a completely separate project. This has to be performed in this manner because the template module is set up following specific formats for the individual project.

If you read my previous post I asked how I can perform a similar function to copying all the objects over, I'm already aware of the bool copy function and how it works, and it does not fulfill what I am trying to do, I'm not trying to copy the module-as I've already said-I'm trying to duplicate the data to a template.

I haven't explicitly looked through copyobj.dxl but I've looked through scripts that co-workers have written based on this script and it seems very complex and convoluted for the ideas that I'm trying to implement.

I was looking at copyHier because if you use the DOORS gui, you can do what I'm attempting to do in DXL, with a few simple mouse clicks. I was trying to find the code that was used to implement those functions in the gui and it appeared that copyHier was the closest thing.
FOR EXAMPLE:
In the gui, if you open two separate modules, in the first module, you can grab an object heading with the mouse and drag it to the second module, at which point a list comes up and you can select "Copy->After (with hierarchy)"

It appears that this is the copyHier function but as I said, I can only get this function to work within the same module, not from one module to the next.

If it helps, this script is being written for 8.3.

It seems that the "Copy After (with Hierarchy)" function is an integral part of the DOORS module editor (and not written in DXL). Notice that when you not use drag & drop but try to do "Ctrl-C" in the source module and "Ctrl-V" in the target module (or use the menu) it does not work.

It seems you need to manually write a copy function.

Regards, Mathias

Re: copyHier
ePiallat - Tue Nov 10 04:01:23 EST 2009

John V - Mon Nov 09 12:59:24 EST 2009
I need to copy objects from a module in a static "library or collection" if you will-a "library or collection" that will stay the same forever-to a blank template module in a completely separate project. This has to be performed in this manner because the template module is set up following specific formats for the individual project.

If you read my previous post I asked how I can perform a similar function to copying all the objects over, I'm already aware of the bool copy function and how it works, and it does not fulfill what I am trying to do, I'm not trying to copy the module-as I've already said-I'm trying to duplicate the data to a template.

I haven't explicitly looked through copyobj.dxl but I've looked through scripts that co-workers have written based on this script and it seems very complex and convoluted for the ideas that I'm trying to implement.

I was looking at copyHier because if you use the DOORS gui, you can do what I'm attempting to do in DXL, with a few simple mouse clicks. I was trying to find the code that was used to implement those functions in the gui and it appeared that copyHier was the closest thing.
FOR EXAMPLE:
In the gui, if you open two separate modules, in the first module, you can grab an object heading with the mouse and drag it to the second module, at which point a list comes up and you can select "Copy->After (with hierarchy)"

It appears that this is the copyHier function but as I said, I can only get this function to work within the same module, not from one module to the next.

If it helps, this script is being written for 8.3.

I understand better now, but I'm afraid you can't use the "pasteSame" function to copy into another module.
In the GUI, don't try to drag and drop but select "copy with hierarchy" with the right-click in the first module, then right-click in the second one: "Paste" is greyed out.

Anyway, here you are:

// copyHierarchy.dxl
 
/**
 * Minimal subset from: /DOORS/lib/dxl/example/copyobj.dxl
 * Launch "copyAllVisible" without displaying a DB
 *  
 * @author epiallat
 * @date 10 nov. 2009
 */
 
 
// change source and target here
Module targetMod = edit "Target"
Module sourceMod = read "Source"
 
 
 
#include <example/include/copyops.inc>
 
const int createAfter     = 0
const int createBelow     = 1
const int createLastBelow = 2
 
void copyObject (Object s, t) {
    if (s==t) return
 
    string attrName = ""
 
    copyAttribute_(s,t,"Object Text")
    copyAttribute_(s,t,"Object Heading")
    copyAttribute_(s,t,"Object Short Text")
 
    if (cell s)
    { // copy across the table border attributes if the object is a cell
        copyAttribute_(s,t,"TableTopBorder")
                copyAttribute_(s,t,"TableBottomBorder")
                copyAttribute_(s,t,"TableLeftBorder")
                copyAttribute_(s,t,"TableRightBorder")
                copyAttribute_(s,t,"TableCellWidth")  
                copyAttribute_(s,t,"TableCellAlign")  
    }
}
 
/* Check whether object o is a child of object check */
 
bool childOf(Object check, Object o) {
 
    while (o!=check && o!=null)
        o = parent o
 
    return (o==check)
 
} /* childOf */
 
// Given a starting object, returns the next visible object
// (or null) which is not in the tree under the starting object
Object ftNextValidSkipTree(Object starto) {
 
    Object checko
 
    if (null starto)
        return null
 
    checko = next starto
 
    while ((!null checko) && (childOf(starto, checko) || (!isVisible checko && !table checko && !row checko))) {
        checko = next checko
    }
 
    if ((!null checko) && cell(checko)) {
        /* Move to the table object */
        checko = parent checko
        checko = parent checko
    }
 
    return checko
}
 
// Returns first visible object in a module
Object ftFirstValid(Module m)
{
    Object o = first m
    while ((!null o) && (!isVisible o && !table o && !row o)) {
            o = next o
    }
    return o
}
 
Object createNewObject(int copyPosition, Object tago)
{
    Object newo
 
    current = targetMod
    
    if (null tago) 
    { // no objects in destination module
        if (isShare targetMod) {
            ack "Target module is in edit shareable mode.\nCannot create initial object in target module."
            halt
        }
            newo = create targetMod
    } 
    else if (!canWrite tago) 
    {
        ack "No permission to write to the current object in target module"
         halt
    } 
    else if (isShare targetMod && copyPosition == createAfter &&
              (level tago == 1 || !canWrite parent tago)) 
    {
        ack "Target module is in edit shareable mode.\nNeed permission to write to the parent of the target object"
        //raise d
        halt
    } 
    else if (copyPosition == createAfter)
    {
        newo = create after tago
    } 
    else if (copyPosition == createBelow)
    {
        newo = create below tago
    }
    else if (copyPosition == createLastBelow)
    {
        newo = create last below tago
    }
    return newo
}
 
void copyVisibleTree(Object sourceUnder, targetUnder)
{
    // Copy the (visible) tree under sourceUnder to be under targetUnder
    // Also copy invisible objects that are table objects or row objects
 
    Object sourceo
    for sourceo in all sourceUnder do
    {
        if (isVisible sourceo || table sourceo || row sourceo) 
        {
            Object targo = createNewObject(createLastBelow, targetUnder)
            copyObject(sourceo, targo)
            copyVisibleTree(sourceo, targo)
        } 
        else
        {        
            copyVisibleTree(sourceo, targetUnder)
        }
    }
}
 
current = targetMod
Object latcho = current
if (!null latcho) latcho = last sibling first targetMod
 
Object o, newo
copyDir = createAfter  
// copy all visible trees
 
// get first visible object
o = ftFirstValid sourceMod
while (!null o) 
{
// copy root of tree
        newo = createNewObject(copyDir, latcho)
        copyObject(o, newo)
        
// copy visible tree under it
        copyVisibleTree(o, newo)
        
// step to next visible tree
        o = ftNextValidSkipTree o
        
// move latcho if neccessary
        if (copyDir == createAfter)
            latcho = newo    
}

Re: copyHier
John V - Wed Nov 11 12:29:25 EST 2009

ePiallat - Tue Nov 10 04:01:23 EST 2009

I understand better now, but I'm afraid you can't use the "pasteSame" function to copy into another module.
In the GUI, don't try to drag and drop but select "copy with hierarchy" with the right-click in the first module, then right-click in the second one: "Paste" is greyed out.

Anyway, here you are:

// copyHierarchy.dxl
 
/**
 * Minimal subset from: /DOORS/lib/dxl/example/copyobj.dxl
 * Launch "copyAllVisible" without displaying a DB
 *  
 * @author epiallat
 * @date 10 nov. 2009
 */
 
 
// change source and target here
Module targetMod = edit "Target"
Module sourceMod = read "Source"
 
 
 
#include <example/include/copyops.inc>
 
const int createAfter     = 0
const int createBelow     = 1
const int createLastBelow = 2
 
void copyObject (Object s, t) {
    if (s==t) return
 
    string attrName = ""
 
    copyAttribute_(s,t,"Object Text")
    copyAttribute_(s,t,"Object Heading")
    copyAttribute_(s,t,"Object Short Text")
 
    if (cell s)
    { // copy across the table border attributes if the object is a cell
        copyAttribute_(s,t,"TableTopBorder")
                copyAttribute_(s,t,"TableBottomBorder")
                copyAttribute_(s,t,"TableLeftBorder")
                copyAttribute_(s,t,"TableRightBorder")
                copyAttribute_(s,t,"TableCellWidth")  
                copyAttribute_(s,t,"TableCellAlign")  
    }
}
 
/* Check whether object o is a child of object check */
 
bool childOf(Object check, Object o) {
 
    while (o!=check && o!=null)
        o = parent o
 
    return (o==check)
 
} /* childOf */
 
// Given a starting object, returns the next visible object
// (or null) which is not in the tree under the starting object
Object ftNextValidSkipTree(Object starto) {
 
    Object checko
 
    if (null starto)
        return null
 
    checko = next starto
 
    while ((!null checko) && (childOf(starto, checko) || (!isVisible checko && !table checko && !row checko))) {
        checko = next checko
    }
 
    if ((!null checko) && cell(checko)) {
        /* Move to the table object */
        checko = parent checko
        checko = parent checko
    }
 
    return checko
}
 
// Returns first visible object in a module
Object ftFirstValid(Module m)
{
    Object o = first m
    while ((!null o) && (!isVisible o && !table o && !row o)) {
            o = next o
    }
    return o
}
 
Object createNewObject(int copyPosition, Object tago)
{
    Object newo
 
    current = targetMod
    
    if (null tago) 
    { // no objects in destination module
        if (isShare targetMod) {
            ack "Target module is in edit shareable mode.\nCannot create initial object in target module."
            halt
        }
            newo = create targetMod
    } 
    else if (!canWrite tago) 
    {
        ack "No permission to write to the current object in target module"
         halt
    } 
    else if (isShare targetMod && copyPosition == createAfter &&
              (level tago == 1 || !canWrite parent tago)) 
    {
        ack "Target module is in edit shareable mode.\nNeed permission to write to the parent of the target object"
        //raise d
        halt
    } 
    else if (copyPosition == createAfter)
    {
        newo = create after tago
    } 
    else if (copyPosition == createBelow)
    {
        newo = create below tago
    }
    else if (copyPosition == createLastBelow)
    {
        newo = create last below tago
    }
    return newo
}
 
void copyVisibleTree(Object sourceUnder, targetUnder)
{
    // Copy the (visible) tree under sourceUnder to be under targetUnder
    // Also copy invisible objects that are table objects or row objects
 
    Object sourceo
    for sourceo in all sourceUnder do
    {
        if (isVisible sourceo || table sourceo || row sourceo) 
        {
            Object targo = createNewObject(createLastBelow, targetUnder)
            copyObject(sourceo, targo)
            copyVisibleTree(sourceo, targo)
        } 
        else
        {        
            copyVisibleTree(sourceo, targetUnder)
        }
    }
}
 
current = targetMod
Object latcho = current
if (!null latcho) latcho = last sibling first targetMod
 
Object o, newo
copyDir = createAfter  
// copy all visible trees
 
// get first visible object
o = ftFirstValid sourceMod
while (!null o) 
{
// copy root of tree
        newo = createNewObject(copyDir, latcho)
        copyObject(o, newo)
        
// copy visible tree under it
        copyVisibleTree(o, newo)
        
// step to next visible tree
        o = ftNextValidSkipTree o
        
// move latcho if neccessary
        if (copyDir == createAfter)
            latcho = newo    
}

Thanks for the responses. Much appreciated.